<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/WEB-INF/templates/BasicTemplate.xhtml">

	<ui:define name="content">
		<f:event type="preRenderView"
			listener="#{trainingController.beforeSearch}" />

		<div class="title ui-widget-header ui-corner-all">
			<h:panelGrid style="margin:auto;">
		BUSCAR CAPACITACIONES
		</h:panelGrid>

		</div>

		<h:form id="formSearch">
			<h:panelGrid style="margin:auto;">

				<h:panelGrid style="margin:auto;text-align:center;">
					<p:messages id="messages"></p:messages>
				</h:panelGrid>


				<h:panelGrid columns="6">

					<p:outputLabel value="N° de documento"></p:outputLabel>
					<p:inputText style="width: 180px;"
						value="#{trainingController.candidateDocumentNumberSearch}"></p:inputText>

					<p:outputLabel value="Nombres"></p:outputLabel>
					<p:inputText style="width: 180px;"
						value="#{trainingController.candidateFirstnameSearch}"></p:inputText>

					<p:outputLabel value="Apellidos"></p:outputLabel>
					<p:inputText style="width: 180px;"
						value="#{trainingController.candidateLastnameSearch}"></p:inputText>

					<p:outputLabel value="Area"></p:outputLabel>
					<p:selectOneMenu id="areas"
						value="#{trainingController.areaSelected}">
						<f:selectItem itemValue="0" itemLabel="Todos"></f:selectItem>
						<f:selectItems value="#{trainingController.areas}"></f:selectItems>
						<p:ajax listener="#{trainingController.searchSubAreas}"
							update=":formSearch:subAreas :formSearch:messages"></p:ajax>
					</p:selectOneMenu>
					<p:outputLabel value="Subarea"></p:outputLabel>
					<p:selectOneMenu id="subAreas"
						value="#{trainingController.subAreaSelected}">
						<f:selectItem itemValue="0" itemLabel="Todos"></f:selectItem>
						<f:selectItems value="#{trainingController.subAreas}"></f:selectItems>
					</p:selectOneMenu>

					<p:outputLabel value="Reclutador"></p:outputLabel>
					<p:selectOneMenu id="recruitments"
						value="#{trainingController.recruiterSelected}">
						<f:selectItem itemValue="0" itemLabel="Todos"></f:selectItem>
						<f:selectItems value="#{trainingController.recruiters}"></f:selectItems>
					</p:selectOneMenu>

					<p:outputLabel value="Fecha de capacitación"></p:outputLabel>
					<p:calendar value="#{trainingController.trainingAtSearch}"></p:calendar>

					<p:outputLabel value="Capacitador"></p:outputLabel>
					<p:selectOneMenu id="trainers"
						value="#{trainingController.trainerSelected}">
						<f:selectItem itemValue="0" itemLabel="Todos"></f:selectItem>
						<f:selectItems value="#{trainingController.trainers}"></f:selectItems>
					</p:selectOneMenu>

					<p:outputLabel value="Estado"></p:outputLabel>
					<p:selectOneMenu id="states"
						value="#{trainingController.stateSelected}">
						<f:selectItem itemValue="0" itemLabel="Todos"></f:selectItem>
						<f:selectItems value="#{trainingController.states}"></f:selectItems>
					</p:selectOneMenu>

				</h:panelGrid>


				<h:panelGrid style="margin:auto;text-align:center;">
					<p:commandButton icon="ui-icon-search"
						actionListener="#{trainingController.search}" value="Buscar"
						process="@form"
						update=":formSearch:searchTable :formSearch:messages :formSearch:trainingId :formSearch:editButtom">
					</p:commandButton>
				</h:panelGrid>

			</h:panelGrid>

			<h:panelGrid columns="2">

				<p:commandButton id="editButtom" action="edit_training.xhtml"
					icon="ui-icon-pencil" value="Editar"
					disabled="#{trainingController.trainingSelected==null}">
					<f:param name="trainingId"
						value="#{trainingController.trainingSelected.id}"></f:param>
				</p:commandButton>
				<p:outputLabel id="trainingId"
					value="Capacitación seleccionada: #{trainingController.trainingSelected!=null?trainingController.trainingSelected.id:''}">
				</p:outputLabel>
			</h:panelGrid>

			<p:dataTable value="#{trainingController.trainings}" var="t"
				rowKey="#{t.id}" paginator="true" rows="10" id="searchTable"
				selectionMode="single"
				selection="#{trainingController.trainingSelected}">
				<p:ajax event="rowSelect"
					update=":formSearch:trainingId :formSearch:editButtom" />
				<p:ajax event="rowUnselect"
					update=":formSearch:trainingId :formSearch:editButtom" />

				<p:column headerText="ID" sortBy="#{t.id}">
					<h:outputText value="#{t.id}"></h:outputText>
				</p:column>

				<p:column headerText="DNI"
					sortBy="#{t.interview.candidate.documentNumber}">
					<h:outputText value="#{t.interview.candidate.documentNumber}"></h:outputText>
				</p:column>

				<p:column headerText="Nombres"
					sortBy="#{t.interview.candidate.firstname}">
					<h:outputText value="#{t.interview.candidate.firstname}"></h:outputText>
				</p:column>

				<p:column headerText="Apellidos"
					sortBy="#{t.interview.candidate.lastname}">
					<h:outputText value="#{t.interview.candidate.lastname}"></h:outputText>
				</p:column>

				<p:column headerText="Area"
					sortBy="#{t.interview.candidate.area.area.name}">
					<h:outputText value="#{t.interview.candidate.area.area.name}"></h:outputText>
				</p:column>

				<p:column headerText="Subarea"
					sortBy="#{t.interview.candidate.area.name}">
					<h:outputText value="#{t.interview.candidate.area.name}"></h:outputText>
				</p:column>

				<p:column headerText="Estado" sortBy="#{t.trainingState.name}">
					<h:outputText value="#{t.trainingState.name}"></h:outputText>
				</p:column>


				<p:column headerText="Fecha Capacitación" sortBy="#{t.trainingAt}"
					width="120">
					<h:outputText value="#{t.trainingAt}">
						<f:convertDateTime pattern="dd-MM-yyyy hh:mm:ss a" />
					</h:outputText>
				</p:column>

				<p:column headerText="Capacitador"
					sortBy="#{t.trainer.firstname} #{t.trainer.lastname}">
					<h:outputText value="#{t.trainer.firstname} #{t.trainer.lastname}"></h:outputText>
				</p:column>

				<p:column headerText="Comentarios" sortBy="#{t.comment}">
					<h:outputText value="#{t.comment}"></h:outputText>
				</p:column>

				<p:column headerText="Fecha Creación" sortBy="#{t.createdAt}"
					width="120">
					<h:outputText value="#{t.createdAt}">
						<f:convertDateTime pattern="dd-MM-yyyy hh:mm:ss a" />
					</h:outputText>
				</p:column>

				<p:column headerText="Reclutador"
					sortBy="#{t.recruiter.firstname} #{t.recruiter.lastname}">
					<h:outputText
						value="#{t.recruiter.firstname} #{t.recruiter.lastname}"></h:outputText>
				</p:column>

			</p:dataTable>


		</h:form>
	</ui:define>

</ui:composition>
</html>
